﻿using AntdUI;
using WinFormium;

namespace DataAcquisition
{
    public partial class SelectProjectForm : BaseForm
    {
        #region 属性

        public Formium formium;
        #endregion

        #region 自定义方法
        /// <summary>设备列表
        /// 
        /// </summary>
        public void LoadList()
        {
            List<Project> list = SqlHelper.Inquireable<Project>(null);
            UpdateTable(list);
        }

        /// <summary>更新DataGridView
        /// 
        /// </summary>
        /// <param name="list"></param>
        private void UpdateTable(List<Project> list)
        {
            var antItemList = new List<ProjectItem>();
            foreach (Project item in list)
            {
                antItemList.Add(new ProjectItem(item.ID, item.Number, item.Name, item.StakeMark, item.PipeSpecification, item.PipeLength, item.Medium, item.DesignPressure, item.PipeNature, item.TestType, item.Company, item.ManometerPrecision, item.ManometerRange, item.TemplateID));
            }
            Table1.DataSource = antItemList;
        }
        #endregion

        #region 系统方法
        public SelectProjectForm()
        {
            InitializeComponent();
            FullScreen = true;
            Header.Text = "选择试压工程";
        }

        private void SelectProjectForm_Load(object sender, EventArgs e)
        {

            Table1.Height = this.Height;
            Table1.Columns = new AntdUI.ColumnCollection {
                new AntdUI.Column("Number","工程编号",AntdUI.ColumnAlign.Center),
                new AntdUI.Column("Name","工程名称",AntdUI.ColumnAlign.Center),
                new AntdUI.Column("StakeMark","工程桩号",AntdUI.ColumnAlign.Center),
                new AntdUI.Column("PipeSpecification","管材规格",AntdUI.ColumnAlign.Center),
                new AntdUI.Column("PipeLength","管道长度",AntdUI.ColumnAlign.Center),
                new AntdUI.Column("DesignPressure","设计压力",AntdUI.ColumnAlign.Center),
                new AntdUI.Column("PipeNature","管道性质",AntdUI.ColumnAlign.Center),
                new AntdUI.Column("Testtype","试压类型",AntdUI.ColumnAlign.Center),
                new AntdUI.Column("Company","施工单位",AntdUI.ColumnAlign.Center),
                new AntdUI.Column("ManometerPrecision","压力表精度",AntdUI.ColumnAlign.Center),
                new AntdUI.Column("ManometerRange","压力表量程",AntdUI.ColumnAlign.Center)
            };
            Table1.Spin("正在加载中...", (config) =>
            {
                LoadList();
            });
        }

        private void Table1_CellDoubleClick(object sender, TableClickEventArgs e)
        {
            if (formium is not null)
            {
                if (e.Record is not null)
                {
                    ProjectItem item = (ProjectItem)e.Record;
                    IndexFormium frm = (IndexFormium)formium;
                    frm.projectItem = item;
                    frm.ReloadProjectInfo();
                    this.Close();
                }
            }
            else
            {
                this.Close();
            }
        }
        #endregion
    }
}
